package kasgroup2;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;

class Conference {
    
    private String name;
    private String place;
    private double price;
    private String description;
    private Date startTime;
    private Date endTime;
    private Boolean isActive;
    private ArrayList<Person> personList = null; //participant, speaker, commitee;
    private ArrayList<Hotel> hotelList = null;
    private ArrayList<Activity> activityList = null;
    
    public Conference(
            String p_Name, 
            Double p_Price,
            String p_Place, 
            String p_Description, 
            Date p_StartTime, 
            Date p_EndTime, 
            Boolean p_IsActive
            ) {
        this.name = p_Name;
        this.price = p_Price;
        this.place = p_Place;
        this.description = p_Description;
        this.startTime = p_StartTime;
        this.endTime = p_EndTime;
        this.isActive = p_IsActive;
        this.personList = new ArrayList<Person>();
        this.hotelList = new ArrayList<Hotel>();
        this.activityList = new ArrayList<Activity>();
    }
    
    public Conference(
            String p_Name, 
            Double p_Price,
            String p_Place, 
            String p_Description, 
            Date p_StartTime, 
            Date p_EndTime, 
            Boolean p_IsActive,
            ArrayList<Hotel> p_Hotels,
            ArrayList<Activity> p_Activities
            ) {
        this(p_Name, p_Price, p_Place, p_Description, p_StartTime, p_EndTime, p_IsActive);
        this.hotelList = p_Hotels;
        this.activityList = p_Activities;
    }
    
    public void addPerson(Person p) {
        this.personList.add(p);
    }
    
    public void addActivity(Activity a) {
        this.activityList.add(a);
    }
    
    public void addHotel(Hotel h) {
        this.hotelList.add(h);
    }

    public String getName() {
        return name;
    }
    
    public Double getPrice() {
        return price;
    }

    public String getPlace() {
        return place;
    }

    public Date getStartTime() {
        return startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public String getDescription() {
        return description;
    }

    public ArrayList<Person> getPersonList() {
        return personList;
    }

    public ArrayList<Hotel> getHotelList() {
        return hotelList;
    }

    public ArrayList<Activity> getActivityList() {
        return activityList;
    }

    public Boolean getIsActive() {
        return isActive;
    }
    
    public ArrayList<Speaker> getSpeakerList() {
        ArrayList<Speaker> speakerList = new ArrayList<Speaker>();
        for(Person p : personList) {
            if(Person.IsSpeaker(p)) {
                speakerList.add((Speaker)p);
            }
        }
        return speakerList;
    }
    
    public ArrayList<Participant> getParticipantList() {
        ArrayList<Participant> participantList = new ArrayList<Participant>();
        for(Person p : personList) {
            if(Person.IsParticipant(p)) {
                participantList.add((Participant)p);
            }
        }
        return participantList;
    }
    
    public ArrayList<Companion> getCompanionList() {
        ArrayList<Companion> companionList = new ArrayList<Companion>();
        for(Person p : personList) {
            if(Person.IsCompanion(p)) {
                companionList.add((Companion)p);
            }
        }
        return companionList;
    }

    public void setDescription(String p_Description) {
        this.description = p_Description;
    }

    public void setPlace(String p_Place) {
        this.place = p_Place;
    }

    public void setStart(Date p_Start) {
        this.startTime = p_Start;
    }

    public void setEnd(Date p_End) {
        this.endTime = p_End;
    }

    public void setIsActive(Boolean p_IsActive) {
        this.isActive = p_IsActive;
    }

    public void updateSpeakers(ArrayList<Speaker> p_SpeakerList) {
        Iterator<Person> it = personList.listIterator();
        while(it.hasNext()) {
            if(Person.IsSpeaker(it.next())) {
                it.remove();
            }
        }
        personList.addAll(p_SpeakerList);
    }

    public void setActivityList(ArrayList<Activity> p_ActivityList) {
        this.activityList = p_ActivityList;
    }
    
    public Boolean removeSpeakerSubject(String p_SpeakerName, String p_SubjectName) {
        Iterator<Speaker> it = getSpeakerList().iterator();
        while(it.hasNext()) {
            Speaker speaker = it.next();
            if(speaker.getName().equals(p_SpeakerName)) {
                System.out.println("Found speaker!");
                for(Subject s : speaker.getSubjectList()) { 
                    if(s.getName().equals(p_SubjectName)) {
                        it.remove();
                        System.out.println("Subject was removed");
                        return true;
                    }
                }
            }
        }
        return false;
    }
    
    public ArrayList<Person> getPersonsInHotel(Object hotelName) {
        ArrayList<Person> pList = new ArrayList<Person>();
        if(hotelName != null) {
            for(Person p : personList) {
                for(HotelRoomGuest hrg : p.getHotelRooms()) {
                    System.out.println(hrg.getHotel().getName() + " - " + hotelName);
                    if(hrg.getHotel().getName().equals(hotelName.toString())) {
                        System.out.println("Added: " + p.getName());
                        pList.add(p);
                    }
                }
            }
        }
        return pList;
    }
}